package book;

import java.util.Arrays;
import java.util.Scanner;

public class BookList {
    private int useSize ;
    public static final int MAXSIZE_BOOK = 10 ;
    private Book[] getBooks ;
    private int getBookSize ;
    private Book[] books = new Book[MAXSIZE_BOOK] ;
    public BookList(){

        this.books[0] = new Book("黑猫警长","老艺术家",10);
        this.books[1] = new Book("葫芦娃","上海美术",8);
        this.books[2] = new Book("三体","刘慈欣",12);
      this.useSize = 3 ;
    }

    public void  showBook(){
        for (int i = 0; i < this.useSize; i++) {
            System.out.println(books[i]);
        }

    }
    public void getBook(int ret){
      this.getBooks = new Book[MAXSIZE_BOOK] ;
      this.getBookSize = 0 ;
      this.getBooks[this.getBookSize] = this.books[ret] ;
        this.getBookSize++;
        delBook(ret);

    }
    public void setBook(int pos , Book book){
        this.books[pos] = book ;
        this.useSize ++ ;
    }

    public int getUseSize(){
        return this.useSize ;
    }
    public int findBook(){
        Scanner scan = new Scanner(System.in) ;
        String bookName = scan.nextLine() ;
        int num = 0 ;
        for (int i = 0; i < this.useSize; i++) {
            if (this.books[i].getName().equals(bookName)) {
                System.out.println(this.books[i]);
                num = 1 ;
                 return i ;
            }
        }
         return -1 ;
    }
      public void delBook(int ret){

          if(ret == MAXSIZE_BOOK - 1){
              this.books[ret] = null ;
          }else if(ret == -1){
              System.out.println("没有找到你要删除的图书");
          }else {
              for (int i = ret; i < this.books.length-1; i++) {
                  this.books[i] = this.books[i + 1] ;
              }
              this.useSize -- ;
          }
      }
    public int findGetBook(){
        Scanner scan = new Scanner(System.in) ;
        String bookName = scan.nextLine() ;
        int num = 0 ;
        for (int i = 0; i < this.getBookSize; i++) {
            if (this.getBooks[i].getName().equals(bookName)) {
                System.out.println(this.getBooks[i]);
                num = 1 ;
                return i ;
            }
        }
        return -1 ;
    }
    


}
